package com.tjtt.common.gps;

public class Class_gs {
	private double a = 0, A = 0, e2 = 0;
    public double B = 0, L = 0, L0 = 0, l = 0;
    private double t = 0, N = 0, W = 0, g2 = 0;
    private double C0 = 0, C2 = 0, C4 = 0, C6 = 0, C8 = 0, C10 = 0, C12 = 0;
    private double X = 0;
    public double Bf = 0;
    final double p = 206264.8062;
    private double gf2 = 0, tf = 0, Nf = 0, Mf = 0;
    public double r = 0, m = 0;
    public double x = 0, y = 0;//定义正算结果高斯坐标***********************数据出口
    public void get_ab(double aa, double ff)///获取椭球参数****************************************外部入口
    {
        a = aa;
        A = 1 / ff;
    }
    public void get_qssj1(double bb, double ll, double l0)//获取正算起算数据**********************外部入口
    {
        B = bb / 180 * Math.PI;
        L = ll;
        L0 = l0;
        l = (L - l0) * 3600;
    }
    public void jscs1()/////计算椭球相关参数
    {
        e2 = 2 * A - Math.pow(A, 2);
        t = Math.tan(B);
        W = Math.sqrt(1 - e2 * Math.pow(Math.sin(B), 2));
        N = a / W;
        g2 = e2 / (1 - e2) * Math.pow(Math.cos(B), 2);
    }
    public void jsCi()//计算系数Ci
    {
        C0 = 1 + 3.0 / 4 * e2 + 45.0 / 64 * Math.pow(e2, 2) + 175.0 / 256 * Math.pow(e2, 3) + 11025.0 / 16384 * Math.pow(e2, 4) + 43659.0 / 65536 * Math.pow(e2, 5) + 693693.0 / 1048576 * Math.pow(e2, 6);
        C2 = 3.0 / 4 * e2 + 15.0 / 16 * Math.pow(e2, 2) + 525.0 / 512 * Math.pow(e2, 3) + 2205.0 / 2048 * Math.pow(e2, 4) + 72765.0 / 65536 * Math.pow(e2, 5) + 297297.0 / 262144 * Math.pow(e2, 6);
        C4 = 15.0 / 64 * Math.pow(e2, 2) + 105.0 / 256 * Math.pow(e2, 3) + 2205.0 / 4096 * Math.pow(e2, 4) + 10395.0 / 16384 * Math.pow(e2, 5) + 1486485.0 / 2097125 * Math.pow(e2, 6);
        C6 = 35.0 / 512 * Math.pow(e2, 3) + 315.0 / 2048 * Math.pow(e2, 4) + 31185.0 / 13072 * Math.pow(e2, 5) + 165165.0 / 524288 * Math.pow(e2, 6);
        C8 = 315.0 / 16384 * Math.pow(e2, 4) + 3465.0 / 65536 * Math.pow(e2, 5) + 99099.0 / 1048576 * Math.pow(e2, 6);
        C10 = 693.0 / 131072 * Math.pow(e2, 5) + 9009.0 / 524288 * Math.pow(e2, 6);
        C12 = 3003.0 / 2097152 * Math.pow(e2, 6);
        X = a * (1 - e2) * (C0 * B - C2 / 2 * Math.sin(2 * B) + C4 / 4 * Math.sin(4 * B) - C6 / 6 * Math.sin(6 * B) + C8 / 8 * Math.sin(8 * B) - C10 / 10 * Math.sin(10 * B) + C12 / 12 * Math.sin(12 * B));
    }
    public void js_gszb()//计算高斯坐标***************数据出口
    {
        x = X + N / (2.0 * p * p) * Math.sin(B) * Math.cos(B) * l * l + N / (24.0 * Math.pow(p, 4)) * Math.sin(B) * Math.pow(Math.cos(B), 3) * (5.0 - t * t + 9.0 * g2 + 4.0 * Math.pow(g2, 2)) * Math.pow(l, 4) + N / (720.0 * Math.pow(p, 6)) * Math.sin(B) * Math.pow(Math.cos(B), 5) * (61.0 - 58 * t * t + Math.pow(t, 4) + 270 * g2 - 330 * g2 * t * t) * Math.pow(l, 6) + N / (40320 * Math.pow(p, 8)) * Math.sin(B) * Math.pow(Math.cos(B), 7) * (1385 - 3111 * t * t + 543 * Math.pow(t, 4) - Math.pow(t, 6)) * Math.pow(l, 8);
        y = 500000 + N / p * Math.cos(B) * l + N / (6.0 * Math.pow(p, 3)) * Math.pow(Math.cos(B), 3) * (1.0 - t * t + g2) * Math.pow(l, 3) + N / (120.0 * Math.pow(p, 5)) * Math.pow(Math.cos(B), 5) * (5.0 - 18.0 * t * t + Math.pow(t, 4) + 14.0 * g2 - 58.0 * g2 * t * t) * Math.pow(l, 5) + N / (5040.0 * Math.pow(p, 7)) * Math.pow(Math.cos(B), 5) * (61.0 - 479.0 * t * t + 179.0 * Math.pow(t, 4) - Math.pow(t, 6)) * Math.pow(l, 7);
    }


    public void zsrm()////////////////////////正算收敛角和m////////////////////////////////////////////
    {
        r = (Math.sin(B) * l + Math.sin(B) * Math.pow(Math.cos(B), 2) / (3 * p * p) * (1 + 3 * g2 + 2 * Math.pow(g2, 2)) * Math.pow(l, 3) + Math.sin(B) * Math.pow(Math.cos(B), 4) / (15 * Math.pow(p, 4)) * (2 - t * t) * Math.pow(l, 5)) / 3600;
        double lll = l / 3600 / 180 * Math.PI;
        m = 1 + 0.5 * lll * lll * Math.pow(Math.cos(B), 2) * (1 + g2) + 1 / 24 * Math.pow(lll, 4) * Math.pow(Math.cos(B), 4) * (5 - 4 * t * t);
    }
    public void get_datafs(double xx, double yy, double ll0)//反算数据入口*********************************
    {
        x = xx;
        y = yy - 500000;
        L0 = ll0;
    }
    public void jsbf()///////////////////////////////////////迭代计算BF
    {
        jsCi();
        double dBf = 0;
        Bf = x / (C0 * a * (1 - e2));
        do
        {
            dBf = x / (C0 * a * (1 - e2)) + 1 / C0 * (C2 / 2 * Math.sin(2 * Bf) - C4 / 4 * Math.sin(4 * Bf) + C6 / 6 * Math.sin(6 * Bf) - C8 / 8 * Math.sin(8 * Bf) + C10 / 10 * Math.sin(10 * Bf)) - Bf;
            Bf = Bf + dBf;
        } while (Math.abs(dBf) > 0.000000000000001);

    }
    public void js_cs2()////////////////////计算椭球相关参数
    {
        e2 = 2 * A - Math.pow(A, 2);
        tf = Math.tan(Bf);
        W = Math.sqrt(1 - e2 * Math.pow(Math.sin(Bf), 2));
        Nf = a / W;
        Mf = a * (1 - e2) / Math.pow(W, 3);
        gf2 = e2 / (1 - e2) * Math.pow(Math.cos(Bf), 2);
    }
    public void fsbl()////////////////////////////高斯反算
    {
        B = Bf - tf / (2 * Mf * Nf) * y * y + tf / (24 * Mf * Math.pow(Nf, 3)) * (5 + 3 * Math.pow(tf, 2) + gf2 - 9 * gf2 * tf * tf) * Math.pow(y, 4) - tf / (720 * Mf * Math.pow(Nf, 5)) * (61 + 90 * tf * tf + 45 * Math.pow(tf, 4)) * Math.pow(y, 6);
        B = B / Math.PI * 180;
        L = (1 / (Nf * Math.cos(Bf)) * y - 1 / (6 * Math.pow(Nf, 3) * Math.cos(Bf)) * (1 + 2 * tf * tf + gf2) * Math.pow(y, 3) + 1 / (120 * Math.pow(Nf, 5) * Math.cos(Bf)) * (5 + 28 * tf * tf + 24 * Math.pow(tf, 4)) * Math.pow(y, 5)) / Math.PI * 180 + L0;
    }
    public void fsrm()//反算收敛角和m
    {
        r = (p / Nf * y * tf - p * y * y / (3 * Math.pow(Nf, 3)) * (1 + tf * tf - gf2 - 4 * gf2) + p * Math.pow(y, 5) / (15 * Math.pow(Nf, 5)) * tf * (2 + 5 * tf * tf + 3 * Math.pow(tf, 4))) / 3600;
        m = 1 + y * y / (2 * Mf * Nf) + Math.pow(y, 4) / (24 * Math.pow((Mf * Nf), 2));
    }
}
